package com.markus.basic.设计模式.单例模式;

import java.io.Serializable;

/**
 * Author:markusZhang
 * Date:Create in 2020/8/24 16:10
 * todo: 双重检验锁
 */
public class SingleTon3 implements Serializable {
    private static volatile SingleTon3 instance;
    private SingleTon3(){}
    public static SingleTon3 getInstance(){
        //第一步判断就是让实例不为空时，快速返回，避免了加锁浪费时间
        if (instance == null){
            synchronized (SingleTon3.class){
                //第二重检验，保证线程拿到锁之后确实 实例是空的
                if (instance == null){
                    instance = new SingleTon3();
                }
            }
        }
        return instance;
    }
    public Object readResolve(){
        return instance;
    }
}
